import { Level } from 'level';
import path from 'path';

export default {
  init: () => {
    return new Promise(resolve => {
      if (!global.levelDB) {
        const dir = process.env.NODE_ENV === 'development' ? path.join(path.resolve(), 'storage') : path.join(path.resolve(), '../', 'storage');
        global.levelDB = new Level(dir, { valueEncoding: 'json' });
      }
      resolve(global.levelDB);
    });
  },
  db: global.levelDB
}
